package com.example.week02.day2.Activity;

import android.os.Bundle;
import android.util.Log;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.week02.R;
import com.example.week02.day2.adapters.MoreTypeAdapter;
import com.example.week02.day2.beans.Datas;
import com.example.week02.day2.beans.ItemBean;
import com.example.week02.day2.beans.MoreTypeBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

//多种条目类型
public class MortType extends AppCompatActivity {

    private static final String TAG = "MoreType---";

    RecyclerView recycler_view;

    private List<MoreTypeBean> mdata;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_mort_type);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        // 绑定 Toolbar 并设置为支持操作栏
        Toolbar toolbar = findViewById(R.id.toolbar_2);
        setSupportActionBar(toolbar);  // 关键步骤：启用菜单支持

        //找到RecyclerView
        recycler_view = findViewById(R.id.more_type);

        //准备数据
        mdata = new ArrayList<>();
        initData();

        //创建或设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recycler_view.setLayoutManager(linearLayoutManager);

        //创建适配器
        MoreTypeAdapter moreTypeAdapter = new MoreTypeAdapter(mdata);
        //设置适配器
        recycler_view.setAdapter(moreTypeAdapter);
    }



    private void initData() {
        Random random = new Random();
        for (int i = 0; i < Datas.icons.length; i++) {
            //创建数据对象
            MoreTypeBean data = new MoreTypeBean();
            data.pic = Datas.icons[i];
            data.type1= random.nextInt(3);
            Log.d(TAG,"type---"+data.type1);
            //添加到集合里头
            mdata.add(data);
        }
    }


}